package com.esm.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


import com.esm.dao.SelectUserDao_zxk;
import com.esm.daoimpl.SelectUserDaoimpl_zxk;

import net.sf.json.JSONObject;
/**
 * 通过姓名获取uid
 * @author 康少
 *
 * 2017年1月9日
 */
public class GetUidByUnameController_zxk extends HttpServlet{
	SelectUserDao_zxk seleuid = new SelectUserDaoimpl_zxk();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		HttpSession session = req.getSession();
		String uname = req.getParameter("uname");
		int uid = seleuid.getUidByUname(uname);
		PrintWriter pw = resp.getWriter();
		JSONObject jo = new JSONObject();
		if (uid != 0) {
			session.removeAttribute("uid");
			session.setAttribute("uid", uid);
			jo.put("temp", 1);
			pw.write(jo.toString());
			pw.flush();
			pw.close();
		} else {
			jo.put("temp", 0);
			pw.write(jo.toString());
			pw.flush();
			pw.close();
		}
		
	}
}
